Changes to improve menu positioning on Xinerama (#108328):
authorMatthias Clasen <maclas@gmx.de>
Wed, 12 Nov 2003 20:53:03 +0000 (20:53 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Wed, 12 Nov 2003 20:53:03 +0000 (20:53 +0000)
Wed Nov 12 21:40:10 2003  Matthias Clasen  <maclas@gmx.de>

Changes to improve menu positioning on Xinerama (#108328):

* gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field
to store the monitor on which the menu is to be positioned.

* gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number
in the GtkMenuPrivate struct and fetch the monitor geometry after
calling the position_func, in case it has been changed.

* gtk/gtkmenu.c (gtk_menu_set_monitor): New function
to be used in GtkMenuPositionFunc implementations for setting
the monitor_num field in GtkMenuPrivate.

* gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call
gtk_menu_set_monitor.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtkmenu.c
gtk/gtkmenu.h
gtk/gtkmenuitem.c

index 57d4b3d22c9ec849ad311ea042c347d0602bd895..7bc003ed56309ef6f090520183f9f75169a45635 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Wed Nov 12 21:40:10 2003  Matthias Clasen  <maclas@gmx.de>
+
+       Changes to improve menu positioning on Xinerama (#108328):
+       
+       * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field
+       to store the monitor on which the menu is to be positioned.
+
+       * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number
+       in the GtkMenuPrivate struct and fetch the monitor geometry after
+       calling the position_func, in case it has been changed.
+
+       * gtk/gtkmenu.c (gtk_menu_set_monitor): New function 
+       to be used in GtkMenuPositionFunc implementations for setting
+       the monitor_num field in GtkMenuPrivate.
+
+       * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call 
+       gtk_menu_set_monitor.
+
 Wed Nov 12 21:00:10 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the
index 57d4b3d22c9ec849ad311ea042c347d0602bd895..7bc003ed56309ef6f090520183f9f75169a45635 100644 (file)
@@ -1,3 +1,21 @@
+Wed Nov 12 21:40:10 2003  Matthias Clasen  <maclas@gmx.de>
+
+       Changes to improve menu positioning on Xinerama (#108328):
+       
+       * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field
+       to store the monitor on which the menu is to be positioned.
+
+       * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number
+       in the GtkMenuPrivate struct and fetch the monitor geometry after
+       calling the position_func, in case it has been changed.
+
+       * gtk/gtkmenu.c (gtk_menu_set_monitor): New function 
+       to be used in GtkMenuPositionFunc implementations for setting
+       the monitor_num field in GtkMenuPrivate.
+
+       * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call 
+       gtk_menu_set_monitor.
+
 Wed Nov 12 21:00:10 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the
index 57d4b3d22c9ec849ad311ea042c347d0602bd895..7bc003ed56309ef6f090520183f9f75169a45635 100644 (file)
@@ -1,3 +1,21 @@
+Wed Nov 12 21:40:10 2003  Matthias Clasen  <maclas@gmx.de>
+
+       Changes to improve menu positioning on Xinerama (#108328):
+       
+       * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field
+       to store the monitor on which the menu is to be positioned.
+
+       * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number
+       in the GtkMenuPrivate struct and fetch the monitor geometry after
+       calling the position_func, in case it has been changed.
+
+       * gtk/gtkmenu.c (gtk_menu_set_monitor): New function 
+       to be used in GtkMenuPositionFunc implementations for setting
+       the monitor_num field in GtkMenuPrivate.
+
+       * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call 
+       gtk_menu_set_monitor.
+
 Wed Nov 12 21:00:10 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the
index 57d4b3d22c9ec849ad311ea042c347d0602bd895..7bc003ed56309ef6f090520183f9f75169a45635 100644 (file)
@@ -1,3 +1,21 @@
+Wed Nov 12 21:40:10 2003  Matthias Clasen  <maclas@gmx.de>
+
+       Changes to improve menu positioning on Xinerama (#108328):
+       
+       * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field
+       to store the monitor on which the menu is to be positioned.
+
+       * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number
+       in the GtkMenuPrivate struct and fetch the monitor geometry after
+       calling the position_func, in case it has been changed.
+
+       * gtk/gtkmenu.c (gtk_menu_set_monitor): New function 
+       to be used in GtkMenuPositionFunc implementations for setting
+       the monitor_num field in GtkMenuPrivate.
+
+       * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call 
+       gtk_menu_set_monitor.
+
 Wed Nov 12 21:00:10 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the
index 57d4b3d22c9ec849ad311ea042c347d0602bd895..7bc003ed56309ef6f090520183f9f75169a45635 100644 (file)
@@ -1,3 +1,21 @@
+Wed Nov 12 21:40:10 2003  Matthias Clasen  <maclas@gmx.de>
+
+       Changes to improve menu positioning on Xinerama (#108328):
+       
+       * gtk/gtkmenu.c (struct _GtkMenuPrivate): Add a menu_num field
+       to store the monitor on which the menu is to be positioned.
+
+       * gtk/gtkmenu.[hc] (gtk_menu_position): Store the monitor number
+       in the GtkMenuPrivate struct and fetch the monitor geometry after
+       calling the position_func, in case it has been changed.
+
+       * gtk/gtkmenu.c (gtk_menu_set_monitor): New function 
+       to be used in GtkMenuPositionFunc implementations for setting
+       the monitor_num field in GtkMenuPrivate.
+
+       * gtk/gtkmenuitem.c (gtk_menu_item_position_menu): Call 
+       gtk_menu_set_monitor.
+
 Wed Nov 12 21:00:10 2003  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkinputdialog.c (gtk_input_dialog_init): Clarify the
index 64a9ce7bcb4bf282348ff1f6a9e12d45a0f39a6e..95fa449a0e785c97907c6a7185919399d1a8a6d1 100644 (file)
@@ -1,3 +1,7 @@
+Wed Nov 12 21:52:35 2003  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtk-sections.txt: Add gtk_menu_set_monitor.
+
 Fri Oct 24 13:15:32 2003  Soeren Sandmann  <sandmann@daimi.au.dk>
 
        * gtk/tmpl/gtktoolbar.sgml, gtk/tmpl/gtkseparatortoolitem.sgml:
index cf64afaf3512e9dc4eb76bd43638ee1a0c2ed401..f78d2cb1f25b7931606efe7c50185e551d11bb81 100644 (file)
@@ -1865,6 +1865,7 @@ gtk_menu_detach
 gtk_menu_get_attach_widget
 GtkMenuPositionFunc
 GtkMenuDetachFunc
+gtk_menu_set_monitor
 <SUBSECTION Standard>
 GTK_MENU
 GTK_IS_MENU
index 263d079b16a6e9f50440b6ef0347788cda085604..1d0bcf2b95fb2045b4b3a147f191e7540e4236a3 100644 (file)
@@ -84,6 +84,8 @@ struct _GtkMenuPrivate
 
   guint *heights;
   gint heights_length;
+
+  gint monitor_num;
 };
 
 typedef struct
@@ -3064,7 +3066,6 @@ gtk_menu_position (GtkMenu *menu)
   GdkScreen *screen;
   GdkScreen *pointer_screen;
   GdkRectangle monitor;
-  gint monitor_num;
 
   g_return_if_fail (GTK_IS_MENU (menu));
 
@@ -3092,13 +3093,16 @@ gtk_menu_position (GtkMenu *menu)
       y = MAX (0, (gdk_screen_get_height (screen) - requisition.height) / 2);
     }
 
-  monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+  private = gtk_menu_get_private (menu);
+  private->monitor_num = gdk_screen_get_monitor_at_point (screen, x, y);
 
   push_in = FALSE;
   
   if (menu->position_func)
-    (* menu->position_func) (menu, &x, &y, &push_in, menu->position_func_data);
+    {
+      (* menu->position_func) (menu, &x, &y, &push_in, menu->position_func_data);
+      gdk_screen_get_monitor_geometry (screen, private->monitor_num, &monitor);
+    }
   else
     {
       gint space_left, space_right, space_above, space_below;
@@ -3126,6 +3130,8 @@ gtk_menu_position (GtkMenu *menu)
        * Positioning in the vertical direction is similar: first try below
        * mouse cursor, then above.
        */
+      gdk_screen_get_monitor_geometry (screen, private->monitor_num, &monitor);
+
       space_left = x - monitor.x;
       space_right = monitor.x + monitor.width - x - 1;
       space_above = y - monitor.y;
@@ -3239,7 +3245,6 @@ gtk_menu_position (GtkMenu *menu)
  
   if (GTK_MENU_SHELL (menu)->active)
     {
-      private = gtk_menu_get_private (menu);
       private->have_position = TRUE;
       private->x = x;
       private->y = y;
@@ -3957,3 +3962,32 @@ gtk_menu_real_move_scroll (GtkMenu       *menu,
       break;
     }
 }
+
+
+/**
+ * gtk_menu_set_monitor:
+ * @menu: a #GtkMenu
+ * @monitor_num: the number of the monitor on which the menu should
+ *    be popped up
+ * 
+ * Informs GTK+ on which monitor a menu should be popped up. 
+ * See gdk_screen_get_monitor_geometry().
+ *
+ * This function should be called from a #GtkMenuPositionFunc if the
+ * menu should not appear on the same monitor as the pointer. This 
+ * information can't be reliably inferred from the coordinates returned
+ * by a #GtkMenuPositionFunc, since, for very long menus, these coordinates 
+ * may extend beyond the monitor boundaries or even the screen boundaries. 
+ *
+ * Since: 2.4
+ **/
+void gtk_menu_set_monitor (GtkMenu *menu,
+                          gint     monitor_num)
+{
+  GtkMenuPrivate *priv;
+  g_return_if_fail (GTK_IS_MENU (menu));
+
+  priv = gtk_menu_get_private (menu);
+  
+  priv->monitor_num = monitor_num;
+}
index b430254ba3141a7dd8f02fee6f73f3f423fa1093..5701f5cc9aa08b3900837bcadf284e402f643fbd 100644 (file)
@@ -196,6 +196,8 @@ void       gtk_menu_attach                (GtkMenu             *menu,
                                            guint                top_attach,
                                            guint                bottom_attach);
 
+void       gtk_menu_set_monitor           (GtkMenu             *menu,
+                                           gint                 monitor_num);
 
 #ifndef GTK_DISABLE_DEPRECATED
 #define gtk_menu_append(menu,child)    gtk_menu_shell_append  ((GtkMenuShell *)(menu),(child))
index eca9b46629c7398c0d3d1aca416ea549826bdf15..312c511070e57e6f1597c6bc30cba4f6ecf01ff2 100644 (file)
@@ -1108,6 +1108,8 @@ gtk_menu_item_position_menu (GtkMenu  *menu,
    */
   *x = CLAMP (tx, monitor.x, MAX (monitor.x, monitor.x + monitor.width - twidth));
   *y = ty;
+
+  gtk_menu_set_monitor (menu, monitor_num);
 }
 
 /**